/**
 *
 */

var app = getApp()
Page({
	data: {
		root: app.setting.att_url,
		banner: [],
		goods: [],
		pagetitle:'充值',
		bannerHeight: Math.ceil(290.0 / 750.0 * getApp().screenWidth)
	},
	onPullDownRefresh: function (){
		var the=this;
		var opt={};
		the.onLoad(opt);
		setTimeout(function(){
			wx.stopPullDownRefresh()
		},1000);
	},
	onLoad: function (options){
		var the=this;
		var diydata='';
		var footer='';
		wx.setNavigationBarTitle({'title':the.data.pagetitle});
		app.util.get(app.access,function(pagedata){
			the.setData({
				pagedata: pagedata,
			});
		});
	},
	showcouponmore:function(){
		var the=this;
		var pagedata=the.data.pagedata;
		pagedata.showcouponmore=pagedata.showcouponmore?false:true;
		the.setData({
			'pagedata.showcouponmore': pagedata.showcouponmore,
		});
	},
	setmoney:function(evt){
		var the=this;
		var pagedata=the.data.pagedata;
		var data=e.currentTarget.dataset;
		pagedata.item.money=data.money
		the.setData({
				'pagedata.item': pagedata.item,
		});
	},
	goback: function() {
		var pages=getCurrentPages()
		if(pages.length>1){
			wx.navigateBack({
				'delta':1,
				'fail':function(){
					app.util['access'](app.plugin_name+'/index/');
				},
			})
		}else{
			app.util['access'](app.plugin_name+'/index/');
		}
    },
	click:function(evt){
		//用户点击事件 data.func 为方法名，data.params 为调用参数！
		var data=evt.currentTarget.dataset;
		app.util[data.func](data.params);
	},
	closepaymodal:function(){
		var page=this
		page.setData({
			showpaymodal:false
		});
	},
	pay_credit:function(e){
		var page=this
		var pagedata=page.data.pagedata
		app.util.pay_credit(pagedata.paymodal.id,function(res){
				page.setData({
					showpaymodal:false,
				});
				app.util.msg(res.message,'','goback');
		},pagedata.paymodal.di_open)
	},
	pay_wechat:function(e){
		var page=this
		var pagedata=page.data.pagedata
		app.util.pay_wechat(pagedata.paymodal.id,function(res){
				page.setData({
					showpaymodal:false,
				});
				app.util.msg(res.message,'','goback');
		},pagedata.paymodal.di_open);
	},
	pay_alipay:function(e){
		var page=this
		var pagedata=page.data.pagedata
		app.util.pay_alipay(pagedata.paymodal.id,function(res){
				page.setData({
						showpaymodal:false,
				});
				app.util.msg(res.message,'','goback');
		},pagedata.paymodal.di_open);
	},
    pay_ttpay:function(e){
		var page=this
		var pagedata=page.data.pagedata
		app.util.pay_ttpay(pagedata.paymodal.id,function(res){
				page.setData({
					showpaymodal:false,
				});
				app.util.msg(res.message,'','goback');
		},pagedata.paymodal.di_open)
	},
	pay_kspay:function(e){
		var page=this
		var pagedata=page.data.pagedata
		app.util.pay_kspay(pagedata.paymodal.id,function(res){
				page.setData({
					showpaymodal:false,
				});
				app.util.msg(res.message,'','goback');
		},pagedata.paymodal.di_open)
	},
	pay_hdfk:function(e){
		var page=this
		var pagedata=page.data.pagedata
		app.util.pay_hdfk(pagedata.paymodal.id,function(res){
				page.setData({
					showpaymodal:false,
				});
				app.util.msg(res.message,'','goback');
		})
	},
	pay_apipay:function(e){
		var page=this
		var pagedata=page.data.pagedata
		app.util.pay_apipay(pagedata.paymodal.id,function(res){
				page.setData({
					showpaymodal:false,
				});
				app.util.msg(res.message,'','goback');
		},pagedata.paymodal.di_open,pagedata.paymodal.api_name)
	},
	radiotype:function(e){
		var the=this;
		var value=e.detail.value;
		var data=e.currentTarget.dataset;
		var pagedata=the.data.pagedata
		the.setData({
			'pagedata.paymodal.paytype':data.type,
			'pagedata.paymodal.api_name':data.name
		})
	},
	radiodi_open:function(e){
		var the=this;
		var value=e.detail.value;
		var data=e.currentTarget.dataset;
		var pagedata=the.data.pagedata
		var di_open=pagedata.paymodal.di_open;
		di_open=di_open==data.type?'':data.type;
		if(!di_open){
			data.difee=0;
		}
		the.setData({
			'pagedata.paymodal.di_open':di_open,
			'pagedata.paymodal.di_fee':data.difee
		})
	},
	new_gotopay:function(e){
		var the=this;
		var pagedata=the.data.pagedata
		var paytype=pagedata.paymodal.paytype;
		if(paytype=='credit'){
			the.pay_credit();
		}else if(paytype=='wechat'){
			the.pay_wechat();
		}else if(paytype=='alipay'){
			the.pay_alipay();
		}else if(paytype=='hdfk'){
			the.pay_hdfk();
		}else if(paytype=='apipay'){
			the.pay_apipay();
		}else if(paytype=='ttpay'){
			the.pay_ttpay();
		}else if(paytype=='kspay'){
			the.pay_kspay();
		}else{
			app.util.msg('请选择支付方式！');
		}
	},
	//提交订单
    formSubmit:function(e){
        var that = this;
        var value = e.detail.value;
		app.util.post('core/member.recharge/recharge/',{'money':value.money},function(payid){
			console.log('payid');console.log(payid);
			app.util.pay(payid,function(res){		
				if(res.type=='more'){
					that.setData({
						showpaymodal:true,
						'pagedata.paymodal':res
					});
				}else if(res.type=='success'){
					app.util.message(res.message);
				}else{
					app.util.message(res.message);
				}
			});
		});
    }
})